Skip to content

Conversation

@DenKoren
Copy link

@DenKoren DenKoren commented Sep 2, 2025

When _pick_get_win_folder in platformdirs/windows.py uses registry to find common appdata path and
there is no key in 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Common AppData', configuration loading procedure in PIP throws an exception and fails 'install' procedure.

Error example:

  File "C:\example\venv\Lib\site-packages\pip\_internal\configuration.py", line 70, in get_configuration_files
    os.path.join(path, CONFIG_BASENAME) for path in appdirs.site_config_dirs("pip")
                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\example\venv\Lib\site-packages\pip\_internal\utils\appdirs.py", line 48, in site_config_dirs
    dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\example\venv\Lib\site-packages\pip\_vendor\platformdirs\__init__.py", line 146, in site_config_dir
    ).site_config_dir
      ^^^^^^^^^^^^^^^
  File "C:\example\venv\Lib\site-packages\pip\_vendor\platformdirs\windows.py", line 67, in site_config_dir
    return self.site_data_dir
           ^^^^^^^^^^^^^^^^^^
  File "C:\example\venv\Lib\site-packages\pip\_vendor\platformdirs\windows.py", line 56, in site_data_dir
    path = os.path.normpath(get_win_folder("CSIDL_COMMON_APPDATA"))
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\example\venv\Lib\site-packages\pip\_vendor\platformdirs\windows.py", line 209, in get_win_folder_from_registry
    directory, _ = winreg.QueryValueEx(key, shell_folder_name)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified

@ichard26
Copy link
Member

ichard26 commented Sep 2, 2025

I'm afraid that I'm asking you to do more work, but have you investigated whether this would be better fixed in platformdirs instead? This seems like the sort of thing that could be handled with a fallback instead of a registry error. Generally, we prefer to upstream changes to our vendored dependencies over carrying patches (for pip or pip's vendored packages) to keep things maintainable.

Thank you!

@ichard26
Copy link
Member

I've filed an issue with platformdirs to propose a graceful fall back when the registry lookup raises an exception: tox-dev/platformdirs#396.

Since, we avoid—by our vendoring policy—making modifications to our vendored dependencies, I will be closing this pull request as we cannot accept it in its current form. If the platformdirs folks do not address the issue, we would be happy to consider a follow up PR to add error handling within pip's code (although I dread that since this really ought to be platformdirs' problem when you think about the API surface).

Thank you for your interest in improving pip. Hopefully this still results in an improvement, just in the right place! :)

@ichard26 ichard26 closed this Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants